/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package fsdownloadserver;

import com.thoughtworks.xstream.*;
import com.thoughtworks.xstream.io.xml.DomDriver;
import java.io.*;
import java.util.ArrayList;

/**
 *
 * @author
 */
public class ServerInfoLoader {
    private XStream xstream;

    public ServerInfoLoader(){
        xstream = new XStream(new DomDriver());
        xstream.alias("ServerInfo", ServerInfo.class);
        xstream.alias("ServerList", ArrayList.class);
    }

    public ArrayList<ServerInfo> LoadInfo(String path){
        try{
            FileInputStream istream = new FileInputStream(path);
            return (ArrayList<ServerInfo>) xstream.fromXML(istream);

        }
        catch(Exception ex){
            ex.printStackTrace();
            System.exit(1);
        }
        return null;
    }

    public void SaveInfo(String path, ArrayList<ServerInfo> infoList){
        try{
            FileOutputStream ostream = new FileOutputStream(path);
            xstream.toXML(infoList,ostream);
        }
        catch(Exception ex){
            ex.printStackTrace();
            System.exit(2);
        }
    }
}

